<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class GoodsRate extends Model
{
    use HasFactory;

    protected $table = 'sp_goods_rate';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //is_delete 0未删除 1已删除
    const GOODS_RATE_IS_DELETE = 1;//已删除
    const GOODS_RATE_NOT_DELETE = 0;//未删除

    //品类费率
    protected function GetGoodsRate($where)
    {
        $select = array('gr.id', 'gr.source_id', 'gr.fixed_cost', 'gr.goods_rate', 'gr.smartcontract', 'gr.realname', 'gr.risk',
            'gr.platform', 'gr.withhold', 'gr.file', 'gr.financing', 's.source_name','gr.is_preposition','gr.post_deduction');
        $data = $this
            ->from('sp_goods_rate as gr')
            ->leftjoin('sp_source as s', 's.id', 'gr.source_id')
            ->select($select)
            ->where($where)
            ->get();
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    protected function GetOneGoodsRate($where)
    {
        $data = $this
            ->where($where)
            ->first();
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //添加商品费率信息
    protected function addData($data)
    {
        return $data = $this->insert($data);
    }

    //修改商品费率信息
    protected function editData($where, $data)
    {
        return $data = $this->where($where)->update($data);
    }


}
